<?php


/**
 * Model for example application.
 */
class User_Settings extends Psa_Plugin_Model {


	/**
	 * Saves user settings.
	 * @param array $settings values from form. $_POST array.
	 */
	function save_settings($settings){
		
		// input validation object
		$validator = new Psa_Validator();
		
		$validator->add_optional(@$settings['firstname'],'string');
		$validator->add_optional(@$settings['lastname'],'string');
		$validator->add_optional(@$settings['color'],'string');
		$validator->add_optional(@$settings['news'],'int');
		
		$validator->validate();
		
		// get reference to user object from registry
		$user = Psa_Registry::get_instance()->user;
		
		$user->firstname = @$settings['firstname'];
		$user->lastname = @$settings['lastname'];
		$user->color = @$settings['color'];
		$user->news = @$settings['news'];
		
		// save user settings
		$user->save();
	}
	
	
	/**
	 * Puts already saved settings into psa_result object
	 */
	function get_settings(){
		
		// get reference to user object from registry
		$user = Psa_Registry::get_instance()->user;
		
		$this->psa_result->firstname = @$user->firstname;
		$this->psa_result->lastname = @$user->lastname;
		$this->psa_result->color = @$user->color;
		$this->psa_result->news = @$user->news;
	}
}
?>